function moveAnimation2(ele, target) {
    clearInterval(ele.interId);
    ele.interId = setInterval(function() {
        if (ele.offsetLeft == target) {
            clearInterval(ele.interId);
        } else {
            var slowStep = (target - ele.offsetLeft) / 10;
            slowStep = slowStep > 0 ? Math.ceil(slowStep) : Math.floor(slowStep);
            ele.style.left = ele.offsetLeft + slowStep + 'px';
        }
    }, 20);
};
var lun1 = document.getElementsByClassName('pre-sell-banner-lun')[0];
var dors = document.getElementsByClassName('dor');
// 自动轮播函数
var lunbo1;
function autoplay1() {
    // 设置flag 设置让看到第二张图片
    var flag = 1;
     lunbo1 = setInterval(function() {
        // 回滚到flag初始0
        if (flag == dors.length) {
            flag = 0;
        };
        // 设置小圆点的样式
        for (var j = 0; j <dors.length; j++) {
            dors[j].className = "dor";
        };
        dors[flag].className = "dor active";
        // 2.ul进行移动
        var target = flag * (-1920);
        // 走动画
        moveAnimation2(lun1, target);
        // 使flag增加达到ul移动的效果
        flag++;

    }, 3000); 
};
autoplay1();
for (var i = 0; i < dors.length; i++) {
    // 保存i值
    dors[i].index = i;
    // 绑定事件
    dors[i].onmouseenter= function() {
        clearInterval(lunbo1);
        // 1.样式
        for (var j = 0; j < dors.length; j++) {
            dors[j].className = "dor";
        };
        this.className = "dor active";
        // 2.ul进行移动
        var target = this.index * (-1920);
        // 走动画
        moveAnimation2(lun1, target);
    };
};
autoplay1();
// 第二块轮播
var dahezi =document.getElementsByClassName('pre-sell-content-center')[0];
var lunbo2 =document.getElementsByClassName('pre-sell-content-center-ul')[0];
var xiaos = document.getElementsByClassName('xiao');
var next = document.getElementsByClassName('next')[0];
var prev = document.getElementsByClassName('prev')[0];
// 排他函数
var dong;
function paita(ele){
    for(var j=0;j<ele.length;j++){
        ele[j].className = 'xiao';

    }
}
// 移入盒子显示箭头
dahezi.onmouseover=function(){
   
    next.style.display='block';
    prev.style.display='block';
    clearInterval(dong);
}
// 移出盒子隐藏箭头
dahezi.onmouseout=function(){
   
    next.style.display='none';
    prev.style.display='none';
    autoplay();
};
next.onmouseover=function(){
    next.style.backgroundColor='#2B2B2B';
 }
 prev.onmouseover=function(){
    prev.style.backgroundColor='#2B2B2B';
 }
 next.onmouseout=function(){
    next.style.backgroundColor='#C07E97';
 }
 prev.onmouseout=function(){
    prev.style.backgroundColor='#C07E97';
 }


// 定义计数器
var flag1=0;
var count=0;
// 右箭头点击事件
next.onclick=function(){
    flag1++;
    count++;
    if(flag1==xiaos.length){
        flag1=0;
    }
    if(count==lunbo2.children.length){
        lunbo2.style.left=0;
        count=1;    
    }
    paita(xiaos);
        xiaos[flag1].className='xiao piach';
        var target = count*(-600);
        moveAnimation2(lunbo2,target);
}

// 左箭头单击事件
prev.onclick=function(){
    if(count==0){
        count=lunbo2.children.length-1;
        lunbo2.style.left=count*(-600)+'px';
    };
    flag1--;
    count--;
    if(flag1<0){
        flag1=xiaos.length-1;
    }
    // 排他小点
    paita(xiaos);
    xiaos[flag1].className='xiao piach';
    var target=count*(-600);
    moveAnimation2(lunbo2,target);
}

// 封装定时器函数
function autoplay(){
    dong=setInterval(function(){
        next.onclick();
    },3000)
}
autoplay();
// 焦点轮播
for(var i=0;i<xiaos.length;i++){
    xiaos[i].index=i;
    xiaos[i].onmouseenter=function(){
        flag1=this.index;
        count=this.index;
        paita(xiaos);
        this.className='xiao piach';
        var target = this.index*(-600);
        moveAnimation2(lunbo2,target);
    }
}

var hong =document.getElementsByClassName('hong');

for(var i=0;i<hong.length;i++){
    hong[i].onmouseover=function(){
        this.style.color="red";
    }
    hong[i].onmouseout=function(){
       this.style.color="";
   }
}

$('.pre-sell-silde li').mouseenter(function(){
    $(this).css('background-color','#000');
    $(this).siblings().css('background-color','rgba(0, 0, 0, 0.345)')
    $(this).children('a').css('color','red')
    $(this).siblings().children('a').css('color','#fff')
})
$('.pre-sell-silde li').mouseleave(function(){
    $(this).css('background-color','rgba(0, 0, 0, 0.345)');
    $(this).children('a').css('color','#fff')
})